import { ElLoading } from 'element-plus'
import { ref } from 'vue'

export default function useLoading() {
  const loading = ref()
  function openLoading(text?: string) {
    if (loading.value) return
    loading.value = ElLoading.service({
      lock: true,
      text: text || 'Loading',
      background: 'rgba(0, 0, 0, 0.7)',
    })
  }
  function closeLoading() {
    loading.value?.close()
  }
  return { openLoading, closeLoading }
}
